package com.colabo.j2ee.web.oaf.security.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 登录用户模型核心类
 * 用于Spring Security安全框架登录认证后获取的用户模型，封装到Authentication对象中
 * @author Anthony
 *
 */
public class UserDetailsModel implements UserDetails {
	
	private static final long serialVersionUID = -2490337027645328924L;

	// Instance Fields ===================================
	private String password;
	private String username;
	private boolean accountNonExpired = true;
	private boolean accountNonLocked = true;
	private boolean credentialsNonExpired = true;
	private boolean enabled = true;
	
	/** 权限集合*/
	private List authorities;
	/** 功能权限列表*/
	private List fuctionAuthorities;
	
	/** 菜单权限列表*/
	private List menuAuthorities;
	/** url权限列表*/
	private List urlAuthorities;
	/** 上帝模式（-_-!）*/
	private boolean isGod = false;
	
	private boolean isAuth = false;

	// Methods ===================================================
	
	public Collection<GrantedAuthority> getAuthorities() {
		if (authorities != null) {
			return authorities;
		}
		return new ArrayList<GrantedAuthority>();
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setAccountNonExpired(boolean accountNonExpired) {
		this.accountNonExpired = accountNonExpired;
	}

	public void setAccountNonLocked(boolean accountNonLocked) {
		this.accountNonLocked = accountNonLocked;
	}

	public void setCredentialsNonExpired(boolean credentialsNonExpired) {
		this.credentialsNonExpired = credentialsNonExpired;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public void setAuthorities(List authorities) {
		this.authorities = authorities;
	}
	
	public Collection getFuctionAuthorities() {
		return fuctionAuthorities;
	}

	public void setFuctionAuthorities(List fuctionAuthorities) {
		this.fuctionAuthorities = fuctionAuthorities;
	}

	public Collection getMenuAuthorities() {
		return menuAuthorities;
	}

	public void setMenuAuthorities(List menuAuthorities) {
		this.menuAuthorities = menuAuthorities;
	}

	public Collection getUrlAuthorities() {
		return urlAuthorities;
	}

	public void setUrlAuthorities(List urlAuthorities) {
		this.urlAuthorities = urlAuthorities;
	}


	public String getPassword() {
		return password;
	}

	public String getUsername() {
		return username;
	}

	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}

	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}

	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public boolean isAuth() {
		return isAuth;
	}

	public void setAuth(boolean isAuth) {
		this.isAuth = isAuth;
	}

	public boolean isGod() {
		return isGod;
	}

	public void setGod(boolean isGod) {
		this.isGod = isGod;
	}
}
